<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Admin;
class Login extends Controller
{
    public function _initialize(){
        // if (session('aid')) {
        //     $this->redirect('index/index');
        // }
    }
    private $cache_model,$system;
    public function index(){
        if(request()->isPost()) {
            $admin = new Admin();
            $data = input('post.');
            $num = $admin->login($data);
            if($num == 1){
                // return json(['code' => 1, 'msg' => '登录成功!', 'url' => url('index/index')]);
                return $this->redirect('article/list');
            }else {
                $this->assign(['error'=>1]);
                return $this->fetch();
            }
        }else{
            if (input('session.username') && input('session.aid')) {
                return $this->fetch('article/list');
            }
            return $this->fetch();
        }
    }
    public function check($code){
       return captcha_check($code);
    }
}